﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Webcar.Interface;
namespace Webcar.BLL
{
    public class DropDownListManager
    {
        /// <summary>
        /// 绑定登录用户有权限的单位
        /// </summary>
        /// <param name="lc"></param>
        public static void BindDropDownDW(ListControl lc)
        {
            CurrentUser user = new CurrentUser();
            string sql = "select * from dept where isnull(del_flag,'F')='F' and dept_code in "+
                    "(select dept_code  from dbo.BS_MAN_DEPT "+
                    " where man_code='" + CurrentUser.LoginUserID + "')  order by dept_code";
            if (CurrentUser.IsSuperUser())
            {
                sql = "select * from dept where isnull(del_flag,'F')='F' order by dept_code";
            }
            ToolsLayer.PublicFunction.BindList(lc, sql, "dept_code", "dept_name");
        }
        

        public static void BindDropDownDWWithAll(ListControl lc)
        {
            CurrentUser user = new CurrentUser();
            string sql = "select * from dept where isnull(del_flag,'F')='F' and dept_code in " +
                    "(select dept_code  from dbo.BS_MAN_DEPT " +
                    " where man_code='" + CurrentUser.LoginUserID + "')  order by dept_code";
            if (CurrentUser.IsSuperUser())
            {
                sql = "select * from dept where isnull(del_flag,'F')='F'  order by dept_code";
            }
            ToolsLayer.PublicFunction.BindListDefault(lc, sql, "dept_code", "dept_name");
            ListItem li = new ListItem("--全部--", "all");
            li.Selected = true;
            lc.Items.Insert(0, li);
        }

        /// <summary>
        /// 绑定登录用户所属单位的下级单位
        /// </summary>
        /// <param name="lc"></param>
        public static void BindDropDownChildDW(ListControl lc,string child_dept)
        {
            string userid = CurrentUser.LoginUserID;
            string sql = "select * from dept_child where isnull(is_use,'T')='T' and up_dept='" + child_dept + "' and child_dept in (select child_dept from bs_man_childdept where userid='" + userid + "')";
            if(CurrentUser.IsSuperUser())
            {
                sql = "select * from dept_child where up_dept='" + child_dept + "' and isnull(is_use,'T')='T'";
            }
            ToolsLayer.PublicFunction.BindList(lc, sql, "child_dept", "dept_name");
        }
        /// <summary>
        /// 车型大类
        /// </summary>
        /// <param name="lc"></param>
        public static void BindDropDownCarSort(ListControl lc)
        {
            string sql = "select * from v_bs_car_sort";
                    
            ToolsLayer.PublicFunction.BindList(lc, sql, "base_code", "base_name");
        }
        /// <summary>
        /// 车型
        /// </summary>
        /// <param name="lc"></param>
        /// <param name="car_sort"></param>
        public static void BindDropDownCarClass(ListControl lc, string car_sort)
        {
            string sql = "select * from bs_car_class where car_sort = '"+car_sort+"' order by car_note";

            ToolsLayer.PublicFunction.BindList(lc, sql, "car_class", "car_note");
        }
        /// <summary>
        /// 车辆用途
        /// </summary>
        /// <param name="lc"></param>
        public static void BindDropDownCarUse(ListControl lc)
        {
            string sql = "select * from v_car_use";

            ToolsLayer.PublicFunction.BindList(lc, sql, "base_code", "base_name");
        }

        public static void BindDropDownAssertDept(ListControl lc)
        {
            string sql = "select * from v_assept_kind ";

            ToolsLayer.PublicFunction.BindList(lc, sql, "base_code", "base_name");
        }

        public static void BindDropDownSex(ListControl lc)
        {
            ListItem li = new ListItem("男", "1");
            ListItem li2 = new ListItem("女", "0");
            lc.Items.Add(li);
            lc.Items.Add(li2);
            li.Selected = true;
        }
        public static void BindDropDownJobKind(ListControl lc)
        {
            string sql = "select * from v_job_kind ";

            ToolsLayer.PublicFunction.BindList(lc, sql, "base_code", "base_name");
        }
        public static void BindDropDownEducation(ListControl lc)
        {
            string sql = "select * from v_education ";

            ToolsLayer.PublicFunction.BindList(lc, sql, "code", "name");
        }

        public static void BindDropDownSecType(ListControl lc)
        {
            string sql = "select * from v_sec_type ";

            ToolsLayer.PublicFunction.BindList(lc, sql, "base_code", "base_name");
        }

        public static void BindDropDownSecKind(ListControl lc)
        {
            string sql = "select * from v_sec_KInd ";

            ToolsLayer.PublicFunction.BindList(lc, sql, "base_code", "base_name");
        }
        public static void BindDropDownSecDuty(ListControl lc)
        {
            string sql = "select * from v_sec_Duty ";

            ToolsLayer.PublicFunction.BindList(lc, sql, "code", "name");
        }
        public static void BindDropDownReportKind(ListControl lc)
        {
            string sql = "select * from v_report_kind ";

            ToolsLayer.PublicFunction.BindList(lc, sql, "base_code", "base_name");
        }
        public static void BindDropDownRepairKind(ListControl lc)
        {
            string sql = "select * from v_repair_kind ";

            ToolsLayer.PublicFunction.BindList(lc, sql, "base_code", "base_name");
        }
    }
}
